package adfc2.tasks;

import adfc2.actions.DropAction;
import adfc2.core.*;

/**
 * Created by IntelliJ IDEA.
 * User: aimozg
 * Date: 29.01.12
 * Time: 2:22
 */
public class DropTask extends Task {
    public final Item item;
    public final int toxy;
    private MoveTask moving;

    public DropTask(Creature actor, Item item, int toxy) {
        super(actor);
        this.item = item;
        this.toxy = toxy;
    }

    @Override
    public Action nextAction() {
        if (item.owner != actor) {
            completed();
            return null;
        } else if (actor.getXY() == toxy) {
            return new DropAction(actor, item);
        } else {
            if (moving == null) moving = new MoveTask(actor, toxy, false);
            return moving.nextAction();
        }
    }

    @Override
    public String shortName() {
        return "drop " + item.shortName();
    }

    @Override
    public String toString() {
        return "DropTask[" + item + "=>" + World.xy2x(toxy) + "," + World.xy2y(toxy) + "]";
    }
}
